package com.woniu.atms.controller.aft;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.atms.entity.G5Passenger;
import com.woniu.atms.service.G5AftTicketService;
import com.woniu.atms.service.G5TicketService;
import com.woniu.atms.util.ResponseResult;
import com.woniu.atms.vo.aft.ticket.AftPassengerTicketVo;
import com.woniu.atms.vo.aft.ticket.AfterTicketsVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.w3c.dom.stylesheets.LinkStyle;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 李涵
 * @title: AftTicketController 后台管理员 车票管理
 * @projectName g5_atms
 * @description: TODO
 * @date 2022/1/17 15:23
 */
@Slf4j
@RestController
@RequestMapping("/api/aft/v1/ticket")
public class AftTicketController {
    @Resource
    private G5AftTicketService g5AftTicketService;

    @RequestMapping("/ticketInfo")
    public ResponseResult<PageInfo<AfterTicketsVo>> findTicket(@RequestBody(required = false) G5Passenger g5Passenger,@RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum){

        //pageHelper常规只能再查询语句之后执行（拦截查询结果）物理分页

        //这里直接对结果集分页，逻辑分页

        List<AfterTicketsVo> afterTicketsVos=g5AftTicketService.findTicket(g5Passenger);
        Integer pageSize=1;
        Page page=new Page(pageNum,1);
        Integer recodeTotal=afterTicketsVos.size();
        page.setTotal(recodeTotal);

        //计算数据下标
        int startIndex = (pageNum - 1) * pageSize;
        int endIndex = Math.min(startIndex + pageSize, recodeTotal);
        page.addAll(afterTicketsVos.subList(startIndex, endIndex));

        return new ResponseResult<>(new PageInfo<>(page));
    }
}
